using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using XEngine;
using Microsoft.Xna.Framework.Input;

using JigLibX;
using Microsoft.Xna.Framework.Graphics;

namespace XEnginePhysicsGame
{
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        XMain X;

        public XArcBallCamera Camera;
        public Scene scene;
        public InputProcessor input;
        
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            X = new XMain(this);

            graphics.PreferredBackBufferWidth = 1920;
            graphics.PreferredBackBufferHeight = 1080;
            graphics.PreferMultiSampling = true;
            graphics.IsFullScreen = true;

            X.Gravity = new Vector3(0, -20, 0);
        }

        protected override void Initialize()
        {
            Camera = new XArcBallCamera(X);
            Camera.ChangeSettings(MathHelper.ToRadians(-90), MathHelper.ToRadians(-30), 6, 30, MathHelper.ToRadians(-60), 0, 18.0f);

            //Camera.Projection = Camera.GenerateProjection(X, 1, XCamera.ProjectionType.Orthographic);

            scene = new Scene(X, this);
            input = new InputProcessor(X, this);

            base.Initialize();
        }

        protected override void LoadContent()
        {
            scene.Load();
            input.Load();

            scene.SpawnPoint = new Vector3(0, 20, 0);
            scene.CurrentBall = scene.AddObject(Scene.ObjectType.Ball, scene.SpawnPoint, new Vector3(0, 0, 0));

            scene.LoadLevel(1);
        }

        protected override void Update(GameTime gameTime)
        {
            scene.Update(gameTime);
            input.Update(gameTime);

            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            X.Renderer.DrawWithBall(gameTime, Camera, scene.Ball);

            base.Draw(gameTime);
        }
    }
}
